import Vue from 'vue'
import Router from 'vue-router'
Vue.use(Router)

const originalPush = Router.prototype.push
const originalReplace = Router.prototype.replace

Router.prototype.push = function push(location, onResolve, onReject) {
  if (onResolve || onReject) {
    return originalPush.call(this, location, onResolve, onReject)
  }
  return originalPush.call(this, location).catch(err => err)
}


Router.prototype.replace = function push(location, onResolve, onReject) {
  if (onResolve || onReject) {
    return originalReplace.call(this, location, onResolve, onReject)
  }
  return originalReplace.call(this, location).catch(err => err)
}

export default new Router({
  routes: [
    {
      path: '/login',
      name: 'login',
      component:() => import('@/views/Login'),
      hidden: true,
      projectHidden: true
    },
    {
      path: '/',
      component:() => import('@/views/Home'),
      name: '',
      projectHidden: true,
      children: [
        { path: '/interfaceProjectList', component:() => import('@/views/interfaceTestProject/ProjectList'), iconCls:'fa fa-plug', name: '接口测试'},
      ]
    },
    {
      path: '/report',
      component:() => import('@/views/interfaceTestProject/HtmlReport'),
      name: 'report',
    },
    {
      path: '/interfaceTestProject/:project_id',
      component:() => import('@/views/Project'),
      name: '项目',
      hidden: true,
      children: [
      {
        path: '/automationTest/:project_id',
        component:() => import('@/views/interfaceTestProject/api/automation/AutomationTest'),
        name: '自动化测试',
        leaf: true,
        child: true,
        children: [
          {   path: '/interfaceTestProject/:project_id/caseSuiteList', component:() => import('@/views/interfaceTestProject/api/automation/CaseSuiteList'), name: '用例列表'},
          {   path: '/interfaceTestProject/:project_id/caseApiList/caseSuiteId=:case_suite_id', component:() => import('@/views/interfaceTestProject/api/automation/CaseApiList'), name: '用例接口列表'},
          {   path: '/interfaceTestProject/:project_id/updateCaseApi/caseSuiteId=:case_suite_id/testingCaseId=:case_id', component:() => import('@/views/interfaceTestProject/api/automation/UpdateCaseApi'), name: '修改用例'}
        ]
      },
        {
            path: '/interfaceTestProject/:project_id/GlobalHost',
            component:() => import('@/views/interfaceTestProject/global/Globalhost'),
            name: 'Host配置',
            leaf: true
        },
        {
            path: '/interfaceTestProject/:project_id/GlobalMail',
            component:() => import('@/views/interfaceTestProject/global/GlobalMail'),
            name: '邮箱配置',
            leaf: true
        },
        {
            path: '/interfaceTestProject/:project_id/GlobalTestDataStorage',
            component:() => import('@/views/interfaceTestProject/global/GlobalTestDataStorage'),
            name: '数据仓库',
            leaf: true
        },
        {
          path: '/interfaceTestProject/:project_id/CronList',
          component:() => import('@/views/interfaceTestProject/api/automation/CronList'),
          name: '定时任务',
          leaf: true
        },
        // {   
        //   path: '/interfaceTestProject/:project_id/projectReport',
        //   component:() => import('@/views/interfaceTestProject/ProjectReport'), 
        //   name: '测试报告', 
        //   leaf: true
        // },
        
      ]
    }
  ]
})
